package com.woniuxy.controller;


import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.entity.User;
import com.woniuxy.service.UsersService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 个人信息的crud
 */
@RestController
@RequestMapping("/users")
public class UsersController {
    @Autowired(required = false)
    UsersService usersService;
    //添加用户
    @ApiOperation(value = "注册")
    @RequestMapping("/addUsers")
    public ResponseEntity addUser(@RequestBody User user) {
        return usersService.addUsers(user);
    }
    //    删除用户
    @ApiOperation(value = "删除用户")
    @RequestMapping("/delect/{id}")
    public ResponseEntity delect(@PathVariable("id") int id){
        return  usersService.delectOne(id);
    }
    //    查询用户
    @ApiOperation(value = "通过id查询用户")
    @RequestMapping("/findUser/{id}")
    public ResponseEntity findUserAccount(@PathVariable("id") int id){
        return usersService.findUserAccount(id);
    }
//    修改用户信息
    @ApiOperation(value = "修改用户信息")
    @RequestMapping("/updata")
    public ResponseEntity updat(  @RequestBody User user  ){
        return usersService.updata(user);
    }


    //    1.1判断原密码是否正确
    @ApiOperation(value = "修改用户密码")
    @RequestMapping("/findPassword/{account}/{password}")
    public ResponseEntity findPassword(@PathVariable("account")String account ,@PathVariable("password") String password){
        System.out.println(account);
        System.out.println(password);
        return  usersService.findPassword(account,password);
    }
//    1.2执行修改密码
    @RequestMapping("/updataPassword/{account}/{passwordNew1}")
    public ResponseEntity updataPassword(@PathVariable("account") String account,@PathVariable("passwordNew1") String password){
        System.out.println("开始修改密码");
        return  usersService.updataPassword(account,password);
    }

// 修改 头像
    @RequestMapping("/updataAvatar/{avatar}/{account}")
    public ResponseEntity updataAvatar(@PathVariable("avatar") String avatar ,@PathVariable("account") String account){
            return  usersService.updataAvatar(avatar,account);
    }

    @ApiOperation(value = "用于人员设置查询所有人员")
    @RequestMapping("/findAllUser")
    public ResponseEntity findAllUser(){
        return usersService.findAllUser();
    }

    @ApiOperation(value = "给某用户设置为某角色")
    @RequestMapping("/setRole/{roleid}/{userid}")
    public ResponseEntity setRole(@PathVariable("roleid") int roleid,@PathVariable("userid") int userid){
        return usersService.setRole(roleid,userid);
    }
}
